//
//  RMLeadViewController.m
//  RMNote
//
//  Created by lanou3g on 16/4/29.
//  Copyright © 2016年 lxf. All rights reserved.
//

#import "RMLeadViewController.h"
#import "RMMainViewController.h"
#import "RMAppDelegate.h"

#define ImgCount 5
@interface RMLeadViewController ()<UIScrollViewDelegate>



@property(nonatomic,strong)UIScrollView * scrolView;
@property(nonatomic,strong)UIPageControl * pageControl;
@property(nonatomic,strong)NSMutableArray * imageArr;
@property(nonatomic,assign)NSInteger index;
@property(nonatomic,strong)UIImageView * imageV1;
@property(nonatomic,strong)UIImageView * imageV2;
@property(nonatomic,strong)UIImageView * imageV3;
@property(nonatomic,strong)UIImageView * imageV4;
@property(nonatomic,strong)UIImageView * imageV5;


@end

@implementation RMLeadViewController


-(NSMutableArray *)imageArr{
    
    if (!_imageArr) {
        _imageArr = [NSMutableArray array];
        for (int i = 1; i <= ImgCount; i++) {
            UIImage *img = [UIImage imageNamed:@"lead1"];
            [_imageArr addObject:img];
        }
    }
    return _imageArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.scrolView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.scrolView.contentSize = CGSizeMake(kScreenWidth * 5, 0);
    self.scrolView.pagingEnabled = YES;
    self.scrolView.showsVerticalScrollIndicator = NO;
    self.scrolView.showsHorizontalScrollIndicator = NO;
    self.scrolView.contentOffset = CGPointMake(0, 0);
    self.scrolView.delegate = self;
    self.index = 0;
    [self.view addSubview:self.scrolView];
    self.pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(kScreenWidth/3,kScreenHeight - 50,kScreenWidth/3, 30)];
    self.pageControl.numberOfPages = ImgCount;
//    self.pageControl.backgroundColor = [UIColor grayColor];
    self.pageControl.currentPageIndicatorTintColor = kRMMainLineColor;
    self.pageControl.pageIndicatorTintColor = [UIColor whiteColor];
    self.pageControl.alpha = 1;
    self.pageControl.userInteractionEnabled = NO;
    [self.view addSubview:self.pageControl];
    [self creatLeadView];
    
}

-(void)creatLeadView{
    
    for (int i = 0; i<ImgCount; i++) {
        UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0 + kScreenWidth * i, 0, kScreenWidth, kScreenHeight)];
        imgView.image = self.imageArr[i];
        [self.scrolView addSubview:imgView];
        
        if (i == ImgCount - 1) {
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(kScreenWidth/3,kScreenHeight - 100,kScreenWidth/3, 30);
            btn.backgroundColor = [UIColor clearColor];
            [btn setTitle:@"开始体验" forState:(UIControlStateNormal)];
            [btn setTitleColor:kRMMainLineColor forState:UIControlStateNormal];

            [btn addTarget:self action:@selector(goAction) forControlEvents:(UIControlEventTouchUpInside)];
            [imgView addSubview:btn];
            imgView.userInteractionEnabled = YES;
        }
        
    }
}


#pragma mark - UIScrollViewDelegate
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    self.pageControl.currentPage = scrollView.contentOffset.x / kScreenWidth;
}


-(void)goAction{

    RMMainViewController * vc = [[RMMainViewController alloc]init];
    RMAppDelegate *appdelegate = [UIApplication sharedApplication].delegate;
    UINavigationController *nv = [[UINavigationController alloc]initWithRootViewController:[[RMMainViewController alloc]init]];
    appdelegate.window.rootViewController = nv;
    
//    [self presentViewController:vc animated:YES completion:nil];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
